package cn.com.sinux.spring.utils;

import cn.com.sinux.spring.anotation.ModifyIgnore;

import java.lang.reflect.Field;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by Administrator on 2015/9/11.
 */
public class CloneUtils {

    public static void cloneProperty(Object source, Object target) {
        Field[] fields = source.getClass().getDeclaredFields();
        List<String> properties  = new LinkedList<String>();
        for(Field field : fields){
            ModifyIgnore modifyIgnore = field.getAnnotation(ModifyIgnore.class);
            if(modifyIgnore != null && modifyIgnore.value()){
                properties.add(field.getName());
            }
        }
        String[] array = new String[properties.size()];
        properties.toArray(array);
        BeanUtils.copyProperties(source, target, properties.toArray(array));
    }
}
